package com.ym.controller.admin;

import com.github.pagehelper.PageInfo;
import com.ym.common.utils.page.PageDomain;
import com.ym.core.annotation.Log;
import com.ym.core.domain.APIResponse;
import com.ym.core.domain.BaseController;
import com.ym.medical.domain.entity.SysOperationLogEntity;
import com.ym.medical.domain.param.SysOperationLogQueryParam;
import com.ym.medical.domain.vo.SysOperationLogListPcVO;
import com.ym.medical.service.ISysOperationLogSV;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 系统操作日志Controller
 *
 * @author ym
 * @date 2020-08-17
 */
@Api(tags = "admin-系统操作日志")
@RestController
@Validated
@RequestMapping("/sys/log")
public class SysOperationLogController extends BaseController {

	@Autowired
	private ISysOperationLogSV sysOperationLogSV;

	@ApiOperation("查询系统操作日志列表")
	@Log(dataBase = false, printBody = false, printQuery = true)
	@GetMapping("/list")
	public APIResponse<PageInfo<SysOperationLogListPcVO>> list(@Valid SysOperationLogQueryParam queryParam) {
		PageDomain.startPage();
		List<SysOperationLogListPcVO> list = sysOperationLogSV.selectListPC(queryParam);
		return successPage(list);
	}

	@ApiOperation("获取系统操作日志详细信息")
	@Log(dataBase = false, printBody = false, printQuery = true)
	@GetMapping(value = "/info")
	public APIResponse<SysOperationLogEntity> info(@RequestParam Long id) {
		SysOperationLogEntity data = sysOperationLogSV.selectById(id);
		return successData(data);
	}
	
	@ApiOperation("删除系统操作日志")
	@Log(printQuery = false)
	@PostMapping("/delete")
	public APIResponse delete(@RequestBody @Valid @NotNull Long[] ids) {
		int result = sysOperationLogSV.deleteByIds(ids);
		return successData(result);
	}
}
